<template>
	<view class="order-product-list">
		<view class="order-main ">
			<block v-for="(item, index) in data" :key="index" v-if="(index + 1) % 2 != 0">
				<view class="order-item" hover-class="hover" :hover-start-time="150" 
			         @click="detail(item)">
					<tui-lazyload-img
					 class="order-img" mode="widthFix"
					 width="100%" height="200rpx" :src="getImg(item.img)"></tui-lazyload-img>
					<view class="order-content">
						<view class="order-content-info">
							<view class="order-title">{{item.reqType}}</view>
							<span class="order-time">{{item.orderStartTime.split(" ")[0]}}</span>
						</view>
						
						<view>
							<view class="order-user">
								<view class="order-info">
									<image :src="item.createUserAvatar" class="order-avatar"></image>
									<span class="order-nickname">{{item.createUserName}}</span>
								</view>
							</view>
						</view>
					</view>
				</view>
			</block>
		</view>
		<view class="order-main">
			<block v-for="(item, index) in data" :key="index" v-if="(index + 1) % 2 == 0">
				<view class="order-item" hover-class="hover" :hover-start-time="150" 
			       @click="detail(item)">
					<tui-lazyload-img
					 class="order-img" mode="widthFix"
					 width="100%" height="200rpx" :src="getImg(item.img)"></tui-lazyload-img>
					<view class="order-content">
						<view class="order-content-info">
							<view class="order-title">{{item.reqType}}</view>
							<span class="order-time">{{item.orderStartTime.split(" ")[0]}}</span>
						</view>
					<view>
					<view class="order-user">
						<view class="order-info">
							<image :src="item.createUserAvatar" class="order-avatar"></image>
							<span class="order-nickname">{{item.createUserName}}</span>
						</view>
					</view>
						</view>
					</view>
				</view>
			</block>
		</view>
	</view>
	
</template>

<script>
export default{
	props: {
		data: {}
	},
	data(){
		return {
		}
	},
	methods: {
		getImg(img){
			let url = '';
			if(img == ''){
				url = "/static/img/toast/no_img.png";
			}else {
				let arr = img.split(',');
				url = arr[0];
			}
			return url;
		},
		detail(data){
			if(this.checkReLogin()) return;
			uni.navigateTo({
				url: '/pages/community/orders/order-detail/order-detail?data='+ encodeURIComponent(JSON.stringify(data))
			})
		},
		checkReLogin(){
			let flag = false;
			let userInfo = uni.getStorageSync("user_info");
			if(userInfo == null || userInfo == '' || userInfo.mobile == '' || userInfo.mobile == null){
				uni.switchTab({
					url: '/pages/my/index?tag=relogin'
				})
				flag = true;
				return flag;
			}
			
		},
	}
}
</script>

<style lang="scss">
	@import './orders.css';
</style>